package com.wd.live.view.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.wd.live.R;
import com.wd.live.base.BaseActivity;
import com.wd.live.bean.GaiSexBean;
import com.wd.live.databinding.ActivityGaiSexBinding;
import com.wd.live.model.SpUtils;
import com.wd.live.model.utils.ToastFormat;
import com.wd.live.viewmodel.GaiNameViewModel;

import java.util.HashMap;
import java.util.Map;

public class GaiSexActivity extends BaseActivity<GaiNameViewModel, ActivityGaiSexBinding> {


    private int mysex;

    @Override
    protected void initData() {
        mysex = getIntent().getIntExtra("mysex", 0);
        if(mysex ==1){
            databind.gaisexManrb.setChecked(true);
            databind.gaisexWomanrb.setChecked(false);
            databind.sexMankuang.setVisibility(View.VISIBLE);
            databind.sexWomankuang.setVisibility(View.GONE);
        }else {
            databind.gaisexWomanrb.setChecked(true);
            databind.gaisexManrb.setChecked(false);
            databind.sexWomankuang.setVisibility(View.VISIBLE);
            databind.sexMankuang.setVisibility(View.GONE);
        }
        Map<String, Object> map = new HashMap<>();
        String uid = SpUtils.getString("uid", "");
        String sid = SpUtils.getString("sid", "");
        int userid = Integer.parseInt(uid);
        map.put("sessionId",sid);
        map.put("userId",userid);

        databind.gaisexManrb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                databind.gaisexManrb.setChecked(true);
                databind.gaisexWomanrb.setChecked(false);
                databind.sexMankuang.setVisibility(View.VISIBLE);
                databind.sexWomankuang.setVisibility(View.GONE);
                Log.v("man",1+"");
            }
        });
        databind.gaisexWomanrb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                databind.gaisexWomanrb.setChecked(true);
                databind.gaisexManrb.setChecked(false);
                databind.sexWomankuang.setVisibility(View.VISIBLE);
                databind.sexMankuang.setVisibility(View.GONE);
                Log.v("woman",2+"");
            }
        });
        databind.oversex.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(databind.gaisexWomanrb.isChecked()){
                    mysex =2;
                }else if(databind.gaisexManrb.isChecked()){
                    mysex =1;
                }else {
                    ToastFormat.setText("请选择要修改的性别");
                }
                viewmodel.gaisexlist(map, mysex).observe(GaiSexActivity.this, new Observer<GaiSexBean>() {
                    @Override
                    public void onChanged(GaiSexBean gaiSexBean) {
                        ToastFormat.setText(gaiSexBean.getMessage());
                        ToastFormat.show();
                        if(gaiSexBean.getStatus().equals("0000")){
                            finish();
                        }
                    }
                });
            }
        });
    }

    @Override
    protected int initLayout() {
        return R.layout.activity_gai_sex;
    }

    @Override
    public void onChanged(Object o) {

    }
}